﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebServices.Models;

namespace WebServices.Controllers
{
    public class ReservationController : ApiController
    {
        /*
         * Web API will match any action method whose name contains the HTTP method used to make the request.
         * The convention when naming API controller action methods is to prefix the name with the action method
         */

        /*
         * To decide between the two action methods, the controller looks at the arguments that the contenders
            accept and uses the routing variables to make the best match
         */

        /*
         * We target the other actions in our Reservation API controller using other HTTP methods: POST,
                DELETE, and PUT. This is the foundation for the Representation State Transfer (REST) style of Web API,
                known more commonly as a RESTful service, where an operation is specified by the combination of a URL
                and the HTTP method used to request it.
         */

        /*
         * The other option is to use Attributes
         */
        IReservationRepository repo = ReservationRepository.getRepository();

        public IEnumerable<Reservation> GetAllReservations()
        {
            return repo.GetAll();
        }
        public Reservation GetReservation(int id)
        {
            return repo.Get(id);
        }
        [HttpPost]
        public Reservation CreateReservation(Reservation item)
        {
            return repo.Add(item);
        }
        [HttpPut]
        public bool UpdateReservation(Reservation item)
        {
            return repo.Update(item);
        }
        public void DeleteReservation(int id)
        {
            repo.Remove(id);
        }
    }
}
